package com.web.index;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.News.impl.NewsServiceImpl;
import com.entity.News;
import com.entity.Product;
import com.entity.ProductCategory;
import com.service.product.impl.ProductServiceImpl;
import com.servlet.BaseServlet;

@WebServlet("/IndexServlet")
public class IndexServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
	
	public String index(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//显示三层分类
		List<ProductCategory> list1 = new ProductServiceImpl().finSelectProductCategory(1);
		List<ProductCategory> list2 = new ProductServiceImpl().finSelectProductCategory(2);
		List<ProductCategory> list3 = new ProductServiceImpl().finSelectProductCategory(3);
		//查询所有的商品
		List<Product> productList = new ProductServiceImpl().finSelectProductAll();
		//查询新闻咨询
		List<News> newsList = new NewsServiceImpl().finSelectNews(null);
		//查询分类的结果存入request域中
		request.setAttribute("list", list1);
		request.setAttribute("list2", list2);
		request.setAttribute("list3", list3);
		//查询商品的结果放进request域中
		request.setAttribute("productList", productList);
		request.setAttribute("newsList", newsList);
		
		return "pre/Index";
	}

	@Override
	public Class<?> getServletClass() {
		return IndexServlet.class;
	}

}
